#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
# author: 小菠萝测试笔记
# blog:  https://www.cnblogs.com/poloyy/
# time: 2021/10/9 1:37 下午
# file: base_request.py
"""

import requests
from requests import Session


class BaseRequests(object):
    __req: Session = requests.session()

    # 反射完成单例模式
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, "instance"):
            setattr(cls, "instance", super(BaseRequests, cls).__new__(cls))
        return getattr(cls, "instance")

    def __exit__(self, *args):
        self.__req.close()

    @classmethod
    def get_request(cls) -> Session:
        return cls.__req


baseRequest = BaseRequests.get_request()

if __name__ == "__main__":
    print(baseRequest.request("get", "http://www.baidu.com").text)
